﻿using ShanghaiMetroAPP.MetroDraw;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace ShanghaiMetroAPP.SMAPPControl
{
    /// <summary>
    /// FindStationItem.xaml 的交互逻辑
    /// </summary>
    public partial class FindStationItem : UserControl
    {
        public FindStationItem()
        {
            InitializeComponent();
            DataContextChanged += this.FindStationItem_DataContextChanged;
        }

        private void FindStationItem_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            var station = DataContext as Station;
            if (station != null)
            {
                this.StationName.Text = station.Name;
                if(station.Name.Length > 6)
                {
                    this.StationName.FontSize = 24;
                }
                this.OrderName.Text = station.PinyinName + "," + station.EnName;
                if (station.LineNo != null)
                {
                    var color = MetroDraw.Line.GetInstance(station.LineNo[0])?.Color;
                    if (color == null)
                        color = Colors.DimGray;
                    this.StationRect.Fill =
                          new SolidColorBrush(color.Value);
                }
                LineItemStatck.Children.Clear();
                //根据线路信息，实例化LineItem
                if (station.LineNo != null)
                {
                    for (var index = 0; index < station.LineNo.Length; ++index)
                    {
                        var line = station.LineNo[index];
                        var lineItem = new FindStationLineItem();
                        lineItem.DataContext = line;
                        LineItemStatck.Children.Add(lineItem);
                        if (index != station.LineNo.Length - 1)
                        {
                            var tb = new TextBlock();
                            tb.Width = 5;
                            LineItemStatck.Children.Add(tb);
                        }
                    }
                }
            }

        }
    }
}
